import request from '@/utils/request';
import { da } from 'element-plus/es/locales.mjs';
import { jwtDecode } from 'jwt-decode'; 


// ... existing code ...

// 添加健康记录接口
export function addHealthRecord(data) {
    return request({
        url: '/health/addRecord',
        method: 'post',
        data: data
    }).then(response => {
        console.log('addHealthRecord 接口响应:', response);
        if (response.code === '000') {
            return response;
        } else {
            console.error('addHealthRecord 调用失败:', response.msg);
            throw new Error(response.msg);
        }
    }).catch(error => {
        console.error('addHealthRecord 请求失败:', error);
        throw error;
    });
}

// 更新健康记录接口
export function updateHealthRecord(data) {
    return request({
        url: '/health/updateRecord',
        method: 'put',
        data: data
    }).then(response => {
        console.log('updateHealthRecord 接口响应:', response);
        if (response.code === '000') {
            return response;
        } else {
            console.error('updateHealthRecord 调用失败:', response.msg);
            throw new Error(response.msg);
        }
    }).catch(error => {
        console.error('updateHealthRecord 请求失败:', error);
        throw error;
    });
}

// 删除健康记录接口
export function deleteHealthRecord(data) {
    return request({
        url: '/health/deleteRecord',
        method: 'delete',
        data: data
    }).then(response => {
        console.log('deleteHealthRecord 接口响应:', response);
        if (response.code === '000') {
            return response;
        } else {
            console.error('deleteHealthRecord 调用失败:', response.msg);
            throw new Error(response.msg);
        }
    }).catch(error => {
        console.error('deleteHealthRecord 请求失败:', error);
        throw error;
    });
}

// 查询健康记录接口
export function queryHealthRecord(data) {
    return request({
        url: '/health/queryRecord',
        method: 'post',
        data: data
    }).then(response => {
        console.log('queryHealthRecord 接口响应:', response);
        if (response.code === '000') {
            return response;
        } else {
            console.error('queryHealthRecord 调用失败:', response.msg);
            throw new Error(response.msg);
        }
    }).catch(error => {
        console.error('queryHealthRecord 请求失败:', error);
        throw error;
    });
}

// ... existing code ...